package com.tj.shopping.service.impl;

import com.tj.shopping.entity.Goods;
import com.tj.shopping.mapper.AdminMapper;
import com.tj.shopping.mapper.GoodsMapper;
import com.tj.shopping.service.IGoodsService;
import com.tj.shopping.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GoodsServiceImpl implements IGoodsService {
    private GoodsMapper mapper;
    @Override
    public int add(Goods goods) {
        SqlSession session = MybatisUtil.getSession(true);
        mapper = session.getMapper(GoodsMapper.class);
        return mapper.add(goods);
    }

    @Override
    public Map<String, Object> findall() {
        SqlSession session = MybatisUtil.getSession(true);
        mapper = session.getMapper(GoodsMapper.class);
        List<Map<String,Object>> list1 = mapper.findall();

        Map<String,Object> map2 = new HashMap<>();
        if (null == list1 || list1.isEmpty()){
            map2.put("code",600);
            map2.put("msg","暂无数据");
        } else {
            map2.put("code",200);
            map2.put("msg","成功");
            map2.put("data",list1);

        }
        MybatisUtil.close(session);
        return map2;

    }
}
